<!DOCTYPE html>
<html>
<head>
    <title>入院办理--中软高科-2015</title>
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" href="../Css/bootstrap.css" />
    <link rel="stylesheet" type="text/css" href="../Css/bootstrap-responsive.css" />
    <link rel="stylesheet" type="text/css" href="../Css/style.css" />
    <script type="text/javascript" src="../Js/jquery.js"></script>
    <script type="text/javascript" src="../Js/jquery.sorted.js"></script>
    <script type="text/javascript" src="../Js/bootstrap.js"></script>
    <script type="text/javascript" src="../Js/ckform.js"></script>
    <script type="text/javascript" src="../Js/common.js"></script>

    <style type="text/css">
        body {
            padding-bottom: 40px;
        }
        .sidebar-nav {
            padding: 9px 0;
        }

        @media (max-width: 980px) {
            /* Enable use of floated navbar text */
            .navbar-text.pull-right {
                float: none;
                padding-left: 5px;
                padding-right: 5px;
            }
        }


    </style>
<!--    <script type="text/javascript">-->
<!--	 -->
<!--	-->

<!--		function delAll(){-->
<!--			var alls=document.getElementsByName("check");-->
<!--			var ids=new Array();-->
<!--			for(var i=0;i<alls.length;i++){-->
<!--				if(alls[i].checked){-->
<!--					ids.push(alls[i].value);-->
<!--				}		-->
<!--			}-->
<!--			if(ids.length>0){-->
<!--				if(confirm("确认操作?")){-->
<!--					alert("成功!");-->
<!--				}-->
<!--			}else{-->
<!--				alert("请选中要操作的项");-->
<!--			}-->
<!--		}-->
<!--    </script>-->
</head>
<body>

<form action="index.html" method="get" class="definewidth m20">
<table class="table table-bordered table-hover definewidth m10">
    <tr>
        <td width="10%" class="tableleft">病例号：</td>
        <td><input type="text" name="hosR_id" id="uid" value=""/></td>
		
        <td width="10%" class="tableleft">挂号姓名</td>
        <td><input type="text" name="hosR_name" id="patientName" value=""/></td>
		
        <td width="10%" class="tableleft">科室：</td>
        <td><input type="text" name="dept" id="dept" value=""/></td>
    </tr>
    <tr>
		
        <td width="10%" class="tableleft">住院时间：</td>
		
		  <td colspan="5">
			<input type="text" name="pname" value=""/>&nbsp;至&nbsp;<input type="text" name="pname" value=""/>
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <button class="btn btn-primary" id="btnList" type="button" onclick="toFind()">查询</button>
            <button type="submit" class="btn btn-primary" type="button" onclick="findList()">清空</button>
        </td>
    </tr>
</table>
</form>
   
<table class="table table-bordered table-hover definewidth m10" >
   <thead>
    <tr>
    	<th><input type="checkbox" id="checkall" onChange="checkall();"></th>
        <th>病历号</th>
        <th>姓名</th>
        <th>床位号</th>
        <th>联系电话</th>
        <th>押金</th>
        <th>主治医生</th>
        <th>科室</th>
        <th>状态</th>
        <th>操作</th>
    </tr>
    </thead>
    <tbody id="tbody">
    </tbody>

  </table>

  <table class="table table-bordered table-hover definewidth m10" >
  	<tr><th colspan="5">  <div class="inline pull-right page" id="a">
<!--          <a href='#'  >第一页</a> <a href='#'>上一页</a>     <span class='current'>1</span><a href='#'>2</a><a href='/chinapost/index.php?m=Label&a=index&p=3'>3</a><a href='#'>4</a><a href='#'>5</a>  <a href='#' >下一页</a> <a href='#' >最后一页</a>-->
<!--		  &nbsp;&nbsp;&nbsp;共<span class='current'>32</span>条记录<span class='current'> 1/33 </span>页-->
		  </div>
		 <div><button type="button" class="btn btn-success" id="newNav">添加住院信息</button>&nbsp;&nbsp;&nbsp;
		 <button type="button" class="btn btn-success"  onClick="delAll();">出院</button>&nbsp;&nbsp;&nbsp;
		 <button type="button" class="btn btn-success" onClick="delAll();">退院</button>&nbsp;&nbsp;&nbsp;
		 <button type="button" class="btn btn-success" >导出Excel</button>
		 </div>
		 
		 </th></tr>
  </table>
<script type="text/javascript">
    function fenye(vo) {
        let pageSize=vo.pageSize;
        $("#a").html("<div id=\"b\" name=\"pageDiv\">\n" +
            "\n" +
            "</div>");
        $("#a").append("\t\t  &nbsp;&nbsp;&nbsp;共<span class='current'> "+vo.total+" </span>条记录<span class='current'> "+vo.pages+" </span>页\n");

        if(vo.pageNum!=1)
            $("#b").append("<span name=\"pageSpan\" id=\"first_page\"><a href=\"javascript:void(0)\" onclick=\"findList("+$("#uid").val()+","+$("#patientName").val()+","+$("#dept").val()+",1,"+pageSize+")\">第一页</a></span>");

        if(vo.hasPreviousPage==true){
            $("#b").append("<span name=\"pageSpan\" id=\"pre_page\"><a href=\"javascript:void(0)\" onclick=\"findList("+$("#uid").val()+","+$("#patientName").val()+","+$("#dept").val()+","+(vo.pageNum-1)+","+pageSize+")\">上一页</a></span>");
        }

        for(let i = 0;i<vo.navigatepageNums.length;i++){
            let index = vo.navigatepageNums[i];
            if(vo.pageNum==index){
                $("#b").append("<span name=\"pageSpan\" id=\"page1\"><a href='javascript:void(0)' style=\"color: #ff0000;\" onclick=\"findList("+$("#uid").val()+","+$("#patientName").val()+","+$("#dept").val()+","+index+","+pageSize+")\">"+index+"</a></span>");
            }else{
                $("#b").append("<span name=\"pageSpan\" id=\"page1\"><a href='javascript:void(0)' onclick=\"findList("+$("#uid").val()+","+$("#patientName").val()+","+$("#dept").val()+","+index+","+pageSize+")\">"+index+"</a></span>");
            }

        }

        if(vo.hasNextPage==true){
            $("#b").append("<span name=\"pageSpan\" id=\"next_page\"><a href='javascript:void(0)' onclick=\"findList("+$("#uid").val()+","+$("#patientName").val()+","+$("#dept").val()+","+(vo.pageNum+1)+","+pageSize+")\">下一页</a></span>");
        }

        if(vo.isLastPage==false){
            $("#b").append("<span name=\"pageSpan\" id=\"last_page\"><a href='javascript:void(0)' onclick=\"findList("+$("#uid").val()+","+$("#patientName").val()+","+$("#dept").val()+","+(vo.pages)+","+pageSize+")\">最后一页</a></span>");
        }

    }

    function toFind(){
        let uid=$("#uid").val();
        let patientName=$("#patientName").val();
        let dept=$("#dept").val();
        findList(uid,patientName,dept);
    }

function findList(id, patientName, dept, pageNum,pageSize){
    $.ajax({
        url:"/patient/inHospital",
        method:"GET",
        data:{
            id: id,
            patientName: patientName,
            dept: dept,
            pageNum:pageNum,
            pageSize:pageSize
        },
        dataType: "json",
        success:function (vo){
            let data = vo.list;
            var str="";
            for(let i=0;i<data.length;i++){
                let hosR_id=data[i].patients[0].id;
                let hosR_name=data[i].patients[0].patientName;
                let beH_patBed=data[i].bedNumber;
                let hosR_phone=data[i].patients[0].patientPhoneNum;
                let beH_antecedent=data[i].deposit==0?'无押金':data[i].deposit;//押金
                let doctorName=data[i].patients[0].doctor;
                let dept=data[i].patients[0].patientDept;
                let hosR_state=data[i].patients[0].status==1?'已住院':'已挂号';//住院状态
                str+="<tr >\n" +
                    "<td style=\"vertical-align:middle\"><input type=\"checkbox\" name=\"check\" value=\""+hosR_id+"\"></td>\n" +
                    "        <td style=\"vertical-align:middle\">"+hosR_id+"</td>\n" +
                    "        <td style=\"vertical-align:middle\">"+hosR_name+"</td>\n" +
                    "        <td style=\"vertical-align:middle\">"+beH_patBed+"</td>\n" +
                    "        <td style=\"vertical-align:middle\">"+hosR_phone+"</td>\n" +
                    "        <td style=\"vertical-align:middle\">"+beH_antecedent+"</td>\n" +
                    "        <td style=\"vertical-align:middle\">"+doctorName+"</td>\n" +
                    "        <td style=\"vertical-align:middle\">"+dept+"</td>\n" +
                    "        <td style=\"vertical-align:middle\">"+hosR_state+"</td>\n" +
                    "        <td style=\"vertical-align:middle;\"><a href='#' onclick=\"lookById("+hosR_id+")\">详情>>></a>&nbsp;&nbsp;&nbsp;<a href='#' onclick=\"editById("+hosR_id+")\">更改</a>&nbsp;&nbsp;&nbsp;" +
                    "<a href='' onclick=\"deleteById("+hosR_id+")\">出院</a></td>\n" +
                    "    </tr>"
            }
            $("#tbody").html(str);
            fenye(vo);
        }
    })
}

    $(() => {
        findList();
    })
    function lookById(id){
        window.location.href="/Hospital/look.html?id="+id;
    }

    function editById(id){
        window.location.href="/Hospital/edit.html?id="+id;
    }

$(function () {
    $('#newNav').click(function(){
        window.location.href="add.html";
    });
});

    function delAll() {
        var alls = document.getElementsByName("check");
        var ids = new Array();
        for (var i = 0; i < alls.length; i++) {
            if (alls[i].checked) {
                ids.push(alls[i].value);
            }
        }
        if (ids.length > 0) {
            if (confirm("确认操作?")) {
                while (ids.length > 0) {
                    let id = ids.pop();
                    $.ajax({
                        url:"/patient/outHospital",
                        data:{
                            id:id
                        },
                        method:"POST",
                        dataType:"json",
                        success:function (vo){

                        }
                    })
                }
                alert("成功!");
                findList();
            }
        } else {
            alert("请选中要操作的项");
        }
    }

function deleteById(id){
    var bol = confirm("你确定要出院吗");
    if(bol){
        //出院
        $.ajax({
            url:"/patient/outHospital",
            data:{
                id:id
            },
            method:"POST",
            dataType:"json",
            success:function (vo){
                findList();
            }
        })
    }else{
        return false;
    }
    }

function checkall(){
    var alls=document.getElementsByName("check");
    var ch=document.getElementById("checkall");
    if(ch.checked){
        for(var i=0;i<alls.length;i++){
            alls[i].checked=true;
        }
    }else{
        for(var i=0;i<alls.length;i++){
            alls[i].checked=false;
        }
    }
}
</script>
</body>
</html>
